Diff.differenceArray   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 2
crap 2
1
import toJson from './toJson.js';
2
3
class Diff {
4
    constructor(currentArray, otherArray, total) {
5 4
        this.currentArray = currentArray;
6 4
        this.otherArray = otherArray;
7 4
        this.total = total;
8
    }
9
10
    get differenceArray() {
11 4
        const otherArray = toJson(this.otherArray);
12 4
        return this.currentArray.filter(
13 12
            (value) => !otherArray.includes(JSON.stringify(value))
14
        );
15
    }
16
17
    get differenceArrayB() {
18 4
        if (!this.total) {
19 2
            return [];
20
        }
21 2
        const currentArray = toJson(this.currentArray);
22
23 2
        return this.otherArray.filter(
24 6
            (value) => !currentArray.includes(JSON.stringify(value))
25
        );
26
    }
27
28
    get compare() {
29 4
        return this.differenceArray.concat(this.differenceArrayB);
30
    }
31
32
    static create(currentArray, otherArray, total) {
33 4
        const differ = new Diff(currentArray, otherArray, total);
34
35 4
        return differ.compare;
36
    }
37
}
38
39
export default function diff(currentArray, otherArray, total) {
40 4
    return Diff.create(currentArray, otherArray, total);
41
}
42